package logic

import (
	"context"
	"fmt"
	"time"
	"we-chat-reg/cache"
	"we-chat-reg/model"
	"we-chat-reg/weixinrpc/internal/svc"
	"we-chat-reg/weixinrpc/weixinrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type PublishLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewPublishLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PublishLogic {
	return &PublishLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *PublishLogic) Publish(in *weixinrpc.PerfectRequest) (*weixinrpc.PerfectResponse, error) {
	// todo: add your logic here and delete this line

	var WeiChant model.WeiChat
	model.DB.Debug().Find(&WeiChant)
	if WeiChant.ID == 0 {
		return nil, fmt.Errorf("该用户未登录")
	}

	cache.Rdb.Set(l.ctx, "content"+in.Tel, 1, time.Hour*2)
	return &weixinrpc.PerfectResponse{
		Id: int64(WeiChant.ID),
	}, nil
}
